package  com.organ.base.service.impl;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.organ.base.entity.SysMember;
import com.organ.base.entity.SysMenu;
import com.organ.base.mapper.SysMemberMapper;
import com.organ.base.service.SysMemberService;
import com.organ.base.service.SysMenuService;

import lombok.AllArgsConstructor;


@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class SysMemberServiceImpl extends ServiceImpl<SysMemberMapper, SysMember> implements SysMemberService {
	
	public HttpSession session;
	
	public SysMenuService sysmService;
	
	@Override
	public String findpwdByMemberNumber(String number) {
		SysMember mb =baseMapper.selectOne(Wrappers.<SysMember>query().lambda().eq(SysMember::getNumber, number));
		return mb.getPassword();
	}

	@Override
	public List<SysMenu> checkMenuAuthority(HttpSession session) {
		String number = (String) session.getAttribute("username");
		SysMember mb =baseMapper.selectOne(Wrappers.<SysMember>query().lambda().eq(SysMember::getNumber, number));
		int authority = mb.getAuthority();
		List<SysMenu> list = null;
		if(authority==0) {
			list=sysmService.list(Wrappers.<SysMenu>query().lambda().eq(SysMenu::getAuthority,authority));
		}
		if(authority==1) {
			list=sysmService.list(Wrappers.<SysMenu>query().lambda());
		}
		return list;
	}
}
